package com.ray.friendslist.token;

import com.ray.friendslist.ContextHolder;

import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.net.Uri;
import android.preference.PreferenceManager;

public class VkTokenManager {

	public static String TOOKEN="TOOKEN";
	
	private static SharedPreferences mPrefs;

	private static Editor mEditor;

	private VkTokenManager() {
	}

	public static String getTooken() {
		mPrefs = PreferenceManager.getDefaultSharedPreferences(ContextHolder.getInstance().getContext());
		String result="";
		return mPrefs.getString(TOOKEN, result);
	}

	public static void setTooken(String url) {
		String s = Uri.parse(url).getEncodedFragment();
		String result = s.substring(s.indexOf("=")+1,s.indexOf("&"));
		mPrefs = PreferenceManager.getDefaultSharedPreferences(ContextHolder.getInstance().getContext());
		mEditor = mPrefs.edit();
		mEditor.putString(TOOKEN,result);
		mEditor.commit();
	}
	
}
